1
2 ///
Credit Danny Goodayle
3 ///
Sourced from - http://www.justapixel.co.uk/radial-layouts-nice-and-simple-in-unity3ds-ui-system/
4 ///
Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
5
6 /*
7 Radial Layout Group
by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk
8 Copyright (c)
2015
9 Permission
is hereby granted, free of charge, to any person obtaining a copy
10 of
this software and associated documentation files (the "Software"), to deal
11 in
the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software
is
14 furnished to
do so, subject to the following conditions:
15 The above copyright notice and
this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */

25
26 namespace
UnityEngine.UI.Extensions
27 {
28     
[AddComponentMenu("Layout/Extensions/Radial Layout")]
29     
public class RadialLayout : LayoutGroup
30     {
31         
public float fDistance;
32         
[Range(0f, 360f)]
33         
public float MinAngle, MaxAngle, StartAngle;
34         
protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
35         
public override void SetLayoutHorizontal()
36         {
37         }
38         
public override void SetLayoutVertical()
39         {
40         }
41         
public override void CalculateLayoutInputVertical()
42         {
43             CalculateRadial();
44         }
45         
public override void CalculateLayoutInputHorizontal()
46         {
47             CalculateRadial();
48         }
49 #
if UNITY_EDITOR
50         
protected override void OnValidate()
51         {
52             
base.OnValidate();
53             CalculateRadial();
54         }
55 #endif
56         
void CalculateRadial()
57         {
58             m_Tracker.Clear();
59             
if (transform.childCount == 0)
60                 
return;
61             
float fOffsetAngle = ((MaxAngle - MinAngle)) / (transform.childCount);
62
63             
float fAngle = StartAngle;
64             
for (int i = 0; i < transform.childCount; i++)
65             {
66                 RectTransform child = (RectTransform)transform.GetChild(i);
67                 
if (child != null)
68                 {
69                     
//Adding the elements to the tracker stops the user from modifiying their positions via the editor.
70                     m_Tracker.Add(
this, child,
71                     DrivenTransformProperties.Anchors |
72                     DrivenTransformProperties.AnchoredPosition |
73                     DrivenTransformProperties.Pivot);
74                     Vector3 vPos =
new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
75                     child.localPosition = vPos * fDistance;
76                     
//Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
77                     child.anchorMin = child.anchorMax = child.pivot =
new Vector2(0.5f, 0.5f);
78                     fAngle += fOffsetAngle;
79                 }
80             }
81
82         }
83     }
84 }


Credit Danny Goodayle

Sourced from - http:www.justapixel.co.ukradial-layouts-nice-and-simple-in-unity3ds-ui-system

Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.

Radial Layout Group by Just a Pixel (Danny Goodayle) - http:www.justapixel.co.uk

Adding the elements to the tracker stops the user from modifiying their positions via the editor.

Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.




Trò chơi đua xe động vật trong UNITY Engine 114.791 lượt xem

Gõ tìm kiếm nhanh...